(function() {
  app.directive('bottomDilog', function() {
    return {
      restrict: 'E',
      templateUrl: 'public/directive/bottom-dilog.html',
      replace: true,
      scope: {},
      controller: function($scope, bottomdilog) {
        $scope.ctrl = bottomdilog;
      }
    };
  });

  app.factory('bottomdilog', function($timeout) {
    return {
      view: false,
      open: function(obj) {
        this.view = true;
        var that = this;
        this.type = obj.type || '1';
        this.closetxt = obj.closetxt || '取消';

        if (obj.cancel) {
          this.cancel = obj.cancel;
        } else {
          this.cancel = function() {
            that.view = false;
          };
        }

        if (this.type === '1') {
          this.question = obj.msg || '';
          this.oktxt = obj.oktxt || '确定';
          this.ok = function() {
            obj.ok();
            that.view = false;
          };
        }

        if (this.type === '2') {
          this.title = obj.title || null;
          this.list = obj.list;
          this.list_click = function(item, index) {
            that.view = false;
            obj.list_click(item, index);
          };
        }
      }

    };
  });
})();